package cn.simple.filetools.poi.excel.support;

import cn.simple.filetools.poi.excel.PoiExcelDataConvertProcessor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author jiangjinjian
 * @date 2024/8/28 8:55
 * @description 通用poi-excel监听器
 */
public class DefaultPoiExcelReadListener<T> extends AbstractPoiExcelReadListener<T> {

    private final List<T> dataList;

    private final List<Map<Integer, String>> head;

    public DefaultPoiExcelReadListener(Class<T> typeClass) {
        this(typeClass, new DefaultPoiExcelDataConvertProcessor());
    }

    public DefaultPoiExcelReadListener(Class<T> typeClass, PoiExcelDataConvertProcessor poiExcelDataConvertProcessor) {
        super(typeClass, poiExcelDataConvertProcessor);
        this.dataList = new ArrayList<>();
        this.head = new ArrayList<>();
    }

    @Override
    public void listenData(T lineData) {
        dataList.add(lineData);
    }

    @Override
    public void listenHead(Map<Integer, String> headMap) {
        head.add(headMap);
    }

    @Override
    public List<T> getData() {
        return this.dataList;
    }

    @Override
    public List<Map<Integer, String>> getHeadMapList() {
        return this.head;
    }

}
